home *** CD-ROM | disk | FTP | other *** search
- head 1.7;
- branch ;
- access ;
- symbols ;
- locks jhh:1.7; strict;
- comment @ * @;
-
-
- 1.7
- date 90.01.02.17.10.46; author ouster; state Exp;
- branches ;
- next 1.6;
-
- 1.6
- date 89.08.23.18.34.47; author douglis; state Exp;
- branches ;
- next 1.5;
-
- 1.5
- date 89.06.16.19.30.20; author mendel; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 89.06.08.09.27.30; author mendel; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.07.25.13.39.33; author ouster; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.07.18.10.53.08; author mendel; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.06.30.11.06.46; author ouster; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.7
- log
- @Convert inet addresses to host byte order.
- @
- text
- @/*
- * Host_Next.c --
- *
- * Source code for the Host_Next library procedure.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/host/RCS/Host_Next.c,v 1.6 89/08/23 18:34:47 douglis Exp $ SPRITE (Berkeley)";
- #endif not lint
-
- #include <stdio.h>
- #include <sprite.h>
- #include <ctype.h>
- #include <host.h>
- #include <hostInt.h>
- #include <stdlib.h>
- #include <string.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
-
- /*
- *-----------------------------------------------------------------------
- *
- * Host_Next --
- *
- * Read the next line from the host file and break it into the
- * appropriate fields of the structure.
- *
- * Results:
- * The return value is a pointer to a Host_Entry structure
- * containing the information from the next line of the file.
- * This is a statically-allocated structure, which will only
- * retain its value up to the next call to this procedure.
- * If the end of the file is reached, or an error occurs, NULL
- * is returned.
- *
- * Side Effects:
- * The position in the file advances.
- *
- *-----------------------------------------------------------------------
- */
- Host_Entry *
- Host_Next()
- {
- #define BUFFER_SIZE 512
- #define MAX_NAMES 20
- static Host_Entry entry;
- static char inputBuf[BUFFER_SIZE];
- static char * fields[MAX_NAMES+2];
- register char * p;
- int numFields;
- int c;
-
- if (hostFile == (FILE *) NULL) {
- return ((Host_Entry *) NULL);
- } else {
- /*
- * First skip any comment lines or blank lines.
- */
-
- while (1) {
- c = getc(hostFile);
- if (c != '#' && c != '\n') {
- break;
- }
- while ((c != '\n') && (c != EOF)) {
- c = getc(hostFile);
- }
- }
- ungetc(c, hostFile);
-
- /*
- * <spriteID>
- */
-
- if (fscanf(hostFile, "%d", &entry.id) != 1) {
- return ((Host_Entry *) NULL);
- }
-
- /*
- * <netType> and <netAddr>
- */
-
- if (fscanf(hostFile, "%100s", inputBuf) != 1) {
- return (Host_Entry *) NULL;
- }
- if (strcmp(inputBuf, "ether") == 0) {
- /*
- * A HOST_ETHER route address is the ethernet address of the
- * machine.
- */
- int byte[6];
- entry.netType = HOST_ETHER;
- if (fscanf(hostFile, "%2x:%2x:%2x:%2x:%2x:%2x",
- &byte[0], &byte[1], &byte[2], &byte[3], &byte[4], &byte[5])
- != 6) {
- return (Host_Entry *) NULL;
- }
- entry.netAddr.etherAddr[0] = byte[0];
- entry.netAddr.etherAddr[1] = byte[1];
- entry.netAddr.etherAddr[2] = byte[2];
- entry.netAddr.etherAddr[3] = byte[3];
- entry.netAddr.etherAddr[4] = byte[4];
- entry.netAddr.etherAddr[5] = byte[5];
- } else if (strcmp(inputBuf, "inet") == 0) {
- /*
- * A HOST_INET route address is the ethernet address of the
- * first gateway machine. The ip address is taken from the
- * field internetAddr.
- */
- int byte[6];
- entry.netType = HOST_INET;
- if (fscanf(hostFile, "%2x:%2x:%2x:%2x:%2x:%2x",
- &byte[0], &byte[1], &byte[2], &byte[3], &byte[4], &byte[5])
- != 6) {
- return (Host_Entry *) NULL;
- }
- entry.netAddr.etherAddr[0] = byte[0];
- entry.netAddr.etherAddr[1] = byte[1];
- entry.netAddr.etherAddr[2] = byte[2];
- entry.netAddr.etherAddr[3] = byte[3];
- entry.netAddr.etherAddr[4] = byte[4];
- entry.netAddr.etherAddr[5] = byte[5];
-
- } else {
- return (Host_Entry *) NULL;
- }
-
- /*
- * <internetAddr>
- */
-
- if (fscanf(hostFile, "%100s", inputBuf) != 1) {
- return (Host_Entry *) NULL;
- }
- entry.inetAddr.s_addr = ntohl(inet_addr(inputBuf));
-
- /*
- * <machType>: first parse the remainder of the line up into
- * fields.
- */
-
- do {
- c = getc(hostFile);
- } while (isspace(c));
- ungetc(c, hostFile);
- if (fgets(inputBuf, BUFFER_SIZE, hostFile) == NULL) {
- return (Host_Entry *) NULL;
- }
-
- /*
- * If the line didn't all fit in the buffer, throw away the
- * remainder.
- */
-
- for (p = inputBuf; *p !=0; p++) {
- /* Null loop body */
- }
- if (p[-1] != '\n') {
- do {
- c = getc(hostFile);
- } while ((c != '\n') && (c != EOF));
- }
-
- for (p = inputBuf, numFields = 0; *p != 0; numFields++) {
- fields[numFields] = p;
- while (!isspace(*p)) {
- p++;
- }
- *p = 0;
- p++;
- while (isspace(*p)) {
- p++;
- }
- if (numFields == MAX_NAMES+1) {
- break;
- }
- }
- if (numFields < 2) {
- return (Host_Entry *) NULL;
- }
- entry.machType = fields[0];
-
- /*
- * <name> and <aliases>
- */
-
- entry.name = fields[1];
- entry.aliases = &fields[2];
- fields[numFields] = (char *) NULL;
- }
- return &entry;
- }
- @
-
-
- 1.6
- log
- @allow blank lines in file
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/host/RCS/Host_Next.c,v 1.5 89/06/16 19:30:20 mendel Exp Locker: douglis $ SPRITE (Berkeley)";
- d28 1
- d145 1
- a145 1
- entry.inetAddr.s_addr = inet_addr(inputBuf);
- @
-
-
- 1.5
- log
- @Fixed type.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/host/RCS/Host_Next.c,v 1.4 89/06/08 09:27:30 mendel Exp $ SPRITE (Berkeley)";
- d66 1
- a66 1
- * First skip any comment lines
- d71 1
- a71 1
- if (c != '#') {
- d74 1
- a74 1
- do {
- d76 1
- a76 1
- } while ((c != '\n') && (c != EOF));
- @
-
-
- 1.4
- log
- @Added "inet" routes to the hostfile.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Host_Next.c,v 1.3 88/07/25 13:39:33 ouster Exp $ SPRITE (Berkeley)";
- d131 1
- @
-
-
- 1.3
- log
- @Lint.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Host_Next.c,v 1.2 88/07/18 10:53:08 mendel Exp $ SPRITE (Berkeley)";
- d96 4
- d113 19
- @
-
-
- 1.2
- log
- @Added include for <sprite.h> so module will compile.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Host_Next.c,v 1.1 88/06/30 11:06:46 ouster Exp $ SPRITE (Berkeley)";
- d60 1
- a60 2
- char c;
- Boolean gotNewline;
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
- d21 1
- @
-